package com.ngc.mall.common.configure.exception;

import com.ngc.mall.common.configure.response.ResponseCode;

public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = 7038699378517285459L;

    /**
     * 失败
     */
    public static final BusinessException FAILURE = BusinessException.failure("失败");
    /**
     * 数据未找到
     */
    public static final BusinessException RESULT_DATA_NONE = BusinessException.failure("数据未找到");
    /**
     * 无访问权限
     */
    public static final BusinessException PERMISSION_NO_ACCESS =  new BusinessException(ResponseCode.PERMISSION_NO_ACCESS);

    private Integer code;

    private Object data;

    public BusinessException() {
    }

    public BusinessException(String message) {
        super(message);
        this.code = -1;
    }

    public BusinessException(ResponseCode status) {
        super(status.message());
        this.code = status.code();
    }

    public BusinessException(String message, Object data) {
        this(message);
        this.data = data;
    }

    public BusinessException(ResponseCode status, Object data) {
        this(status);
        this.data = data;
    }

    public BusinessException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    /**
     * 创建一个业务失败的异常信息
     *
     * @param message
     * @return
     */
    public static BusinessException failure(String message) {
        return new BusinessException(ResponseCode.FAILURE_CODE, message);
    }


    @Override
    public synchronized Throwable fillInStackTrace() {
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


}

